package cn.edu.service.impl;

import cn.edu.dao.lead_OpusDao;
import cn.edu.dao.lead_WorkDao;
import cn.edu.domain.PageBean;
import cn.edu.domain.opus;
import cn.edu.domain.teach_work;
import cn.edu.service.lead_OpusService;
import cn.edu.service.lead_WorkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Davey chan
 */
@Service
public  class lead_WorkServiceImpl implements lead_WorkService {
  @Autowired
private lead_WorkDao workDao;
    @Override
    public PageBean<teach_work> selectByPageAndcondition(int currentPage, int pageSize, teach_work t) {
        int begin=(currentPage-1)*pageSize;
//        计算查询的条目数
        int size =pageSize;
        String term = t.getTerm();
        if(term !=null && term.length()>0){
            t.setTerm("%"+term+"%");
        }
        String courseName = t.getCourseName();
        if(courseName !=null && courseName.length()>0){
            t.setCourseName("%"+courseName+"%");

        }
        String classname = t.getClassname();
        if(classname!=null && classname.length()>0){
            t.setClassname("%"+classname+"%");

        }
        String faculty = t.getFaculty();
        if(faculty!=null && faculty.length()>0){
            t.setFaculty("%"+faculty+"%");

        }
        List<teach_work> rows = workDao.selectBypage(begin, size,t);
//        查询总记录数
        int totalCount =workDao.selectTotalCount(t);
//封装pageBean
        PageBean<teach_work> pageBean=new PageBean<>();
        pageBean.setRows(rows);
        pageBean.setTotalCount(totalCount);
        return pageBean;
    }


}
